package processingdata.density;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class DensityParser {
	
	public static void main(String args[])throws IOException
	{
		int count=0;
		File inputFile=new File("project3cs424/density/DEC_10_SF1_GCTPH1.ST10.csv");
		BufferedReader inputReader=new BufferedReader(new FileReader(inputFile));
		BufferedWriter outputWriter=new BufferedWriter(new FileWriter(new File("project3cs424/density/popdensity.data")));
		while(inputReader.ready())
		{
			
			String inputLine=inputReader.readLine();
			
			
			String inputLineParts[]=inputLine.split(",");
			//System.out.println(inputLineParts.length);
			if(inputLineParts.length==16)
			{
				count++;
				String densityId=inputLineParts[4];
				float populationDensity=Float.parseFloat(inputLineParts[14]);
				String place=inputLineParts[5]+","+inputLineParts[6];
				String placeParts[]=place.replaceAll("\"", "").split("-");
				String state=placeParts[0].trim();
				String city=placeParts[2].split(",")[0].trim();
				if(!place.contains("Puerto Rico"))
				{
					outputWriter.write(densityId+"\t"+state+"\t"+city+"\t"+populationDensity+"\n");
					System.out.println(inputLine);
				}

				
			}
		}
		System.out.println(count);
	}

}
